#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n, x;
int lose[1010], win[1010], user[1010];
int F[1010];//处理第i个人,使用了x这么多药水 获得的最大价值

int main()
{
	read(n);read(x);
	for (int i = 1; i <= n; i++) 
	{
		read(lose[i]);read(win[i]);read(user[i]);
	}

	for (int i = 1; i <= n; i++) 
	{
		for (int j = x; j >= user[i]; j--) 
			F[j] = std::max(F[j] + lose[i], F[j - user[i]] + win[i]);
		for (int j = user[i]-1; j >= 0; j--) 
			F[j] = F[j] + lose[i];
	}

	printf("%lld", (long long int)5*F[x]);
	return 0;
}
